package com.whty.cms.filewps.common.service.impl;

import com.whty.cms.filewps.common.service.BaseService;
import com.whty.cms.filewps.util.MyMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * Created by Administrator on 2019/2/28 0028.
 */
public abstract class BaseAbstractServiceImpl<T> implements BaseService<T> {
    @Autowired
    protected MyMapper<T> mapper;

    private Class<T> modelClass;    // 当前泛型真实类型的Class

    public BaseAbstractServiceImpl() {
        // 获得具体model，通过反射来根据属性条件查找数据
        ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
        modelClass = (Class<T>) pt.getActualTypeArguments()[0];
    }

    
    public void delete(T record) {
    	mapper.delete(record);
    }
    
    public void deleteByExample(Object example) {
    	mapper.deleteByExample(example);
    }
    
    public void deleteByPrimaryKey(Object key) {
    	mapper.deleteByPrimaryKey(key);
    }
    
    public void insert(T record) {
    	mapper.insert(record);
    }
    
    public void insertList(List<T> recordList) {
    	mapper.insertList(recordList);
    }
    
    public List<T> select(T record) {
    	return mapper.select(record);
    }
    
    public List<T> selectAll(){
    	return mapper.selectAll();
    }
    
    public List<T> selectByExample(Object example){
    	return mapper.selectByExample(example);
    }
    
    public T selectByPrimaryKey(Object key) {
    	return mapper.selectByPrimaryKey(key);
    }
    
    public T selectOne(T record) {
    	return mapper.selectOne(record);
    }
    
    public T selectOneByExample(Object example) {
    	return mapper.selectOneByExample(example);
    }
    
    public void updateByPrimaryKey(T record) {
    	mapper.updateByPrimaryKey(record);
    }
    
    public void updateByExample(T record, Object example) {
    	mapper.updateByExample(record, example);
    }
}
